package com.lxy.cxcyxmmsbackend.sys.config;

import com.lxy.cxcyxmmsbackend.sys.interceptor.PermissionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public PermissionInterceptor permissionInterceptor() {
        return new PermissionInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(permissionInterceptor())
                .addPathPatterns("/**")//拦截所有的路径
                .excludePathPatterns("/qxglUser/login")
                .excludePathPatterns("/qxglRole/selectRole")
                .excludePathPatterns("/keyValue/queryKey")
                .excludePathPatterns("/qxglUser/selectIds")
                .excludePathPatterns("/qxglUser/insertUser")
                .excludePathPatterns("/qxglUser/uploadTX")
                .excludePathPatterns("/cxcyXm/fileUpload")
                .excludePathPatterns("/xmHjqk/uploadHjzm")
                .excludePathPatterns("/xmkj/uploadSjt")
                .excludePathPatterns("/xmfjDsjl/uploadDSFJ")
                .excludePathPatterns("/cxcyXm/uploadJHS")
                .excludePathPatterns("/rest/login.do/info")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //将templates目录下的CSS、JS文件映射为静态资源，防止Spring把这些资源识别成thymeleaf模版
        registry.addResourceHandler("/templates/**.js").addResourceLocations("classpath:/templates/");
        registry.addResourceHandler("/templates/**.css").addResourceLocations("classpath:/templates/");
        //其他静态资源
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //swagger增加url映射
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
